import Vue from "vue"
import Router from "vue-router"
//配置页面路由
import home from "../views/home";
import login from "../views/login";
import users from "../components/users";

import activity from "../components/activity";
import dynamic from "../components/dynamic";

Vue.use(Router);
const router = new Router({

  routes:[
    {
      //路由路径
      path: '/home',
      //路径的组件
      component: home,
      name: home,
      redirect: '/activity',
      children: [
        {
          path: '/activity',
          component: activity
        },
        {
          path:'/users',
          component: users
        },
        {
          path:'/dynamic',
          component: dynamic
        }
      ]
    },
    {
      //路由路径
      path: '/',
      //路径的组件
      component: login,
      name: login,
      redirect: '/login'
    },
    {
      //路由路径
      path: '/login',
      //路径的组件
      component: login,
      name: login
    }
  ]
})
export default router
router.beforeEach((to,from,next)=>{
  if(to.path === '/login')return next();
  const tokenStr = window.sessionStorage.getItem('token')
  if(!tokenStr) return next('/login');
  next();
})
